{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>广告列表</h5>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-2" style="width: 100px">
                        <div class="input-group">
                            <a href="{:url('add_ad')}">
                                <button class="btn btn-outline btn-primary" type="button">添加广告</button>
                            </a>
                        </div>
                    </div>
                    <form name="admin_list_sea" class="form-search" method="post" action="{:url('index')}">
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" id="key" class="form-control" name="key" value=""
                                       placeholder="输入需查询广告标题"/>
                                <span class="input-group-btn"> 
                                    <button type="submit" class="btn btn-primary" lay-submit lay-filter="search"><i
                                            class="fa fa-search"></i> 搜索</button>
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-table"
                           lay-data="{id:'index',height:'full-210',url:'index',method:'post',page:true}"
                           lay-filter="index">
                        <thead>
                        <tr>
                            <th lay-data="{title:'ID',field:'id',width:60,fixed:true,align:'center'}"></th>
                            <th lay-data="{title:'标题',field:'title',width:150}"></th>
                            <th lay-data="{title:'广告位',field:'name',width:150}"></th>
                            <th lay-data="{title:'广告图',field:'images',templet:'#images',width:100,align:'center'}"></th>
                            <th lay-data="{title:'状态',field:'status',templet:'#status',width:100,align:'center'}"></th>
                            <th lay-data="{title:'投放状态',field:'closed',width:100,align:'center'}"></th>
                            <th lay-data="{title:'开始时间',field:'start_date',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'结束时间',field:'end_date',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'链接',field:'link_url',width:200}"></th>
                            <th lay-data="{title:'操作',toolbar:'#toolbar',width:130,fixed:'right',align:'center'}"></th>
                        </tr>
                        </thead>
                    </table>
                    <script type="text/html" id="images">
                        <img src="/static/uploads/ad/{{d.images}}" style="height: 30px"
                             onerror="this.src='/static/admin/images/no_img.jpg'"/>
                    </script>
                    <script type="text/html" id="status">
                        <input type="checkbox" name="status" value="{{d.id}}"  lay-skin="switch" lay-text="开启|关闭" lay-filter="status"
                               {{d.status==1?'checked':''}}>
                    </script>
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-group">
                            <a href="javascript:;" onclick="edit_ad({{d.id}})" class="layui-btn layui-btn-xs">
                                <i class="fa fa-paste"></i> 编辑
                            </a>&nbsp;&nbsp;
                            <a href="javascript:;" onclick="del_ad({{d.id}})" class="layui-btn layui-btn-danger layui-btn-xs">
                                <i class="fa fa-trash-o"></i> 删除
                            </a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>

{include file="public/footer" /}

<script type="text/javascript">
    var form = layui.form, table = layui.table;

    /**
     * 搜索
     */
    form.on('submit(search)', function (data) {
        var data = data.field;
        table.reload('index', {
            where: data
        });
        return false;
    });

    /**
     * 编辑广告
     */
    function edit_ad(id) {

        location.href = './edit_ad/id/' + id;
    }


    /**
     * 删除广告
     */
    function del_ad(id) {
        layer.confirm('确认删除此广告?', {icon: 3, title: '提示'}, function (index) {
            $.getJSON('./del_ad', {'id': id}, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1, time: 1500, shade: 0.1});
                    Ajaxpage(1, 5)
                } else {
                    layer.msg(res.msg, {icon: 0, time: 1500, shade: 0.1});
                }
            });

            layer.close(index);
        })

    }

    /**
     * 广告状态
     */
    form.on('switch(status)', function (obj) {
        $.post("{:url('ad_state')}", {id: this.value}, function (result) {
            //layer.tips(result.msg, obj.othis, {tips: 4});
        });
    });
</script>
</body>
</html>